package com.xingkeduo.business.order.remote;

import com.alibaba.fastjson.JSON;
import com.xingkeduo.business.order.remote.feign.PaymentFeignService;
import com.xingkeduo.dto.payment.PayeeOrderParam;
import com.xingkeduo.dto.payment.PayeeOrderResponseDto;
import com.xingkeduo.dto.payment.RefundDto;
import com.xingkeduo.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author chi  2019-04-28 22:02
 **/
@Service
@Slf4j
public class PaymentRemoteService {

    @Resource
    private PaymentFeignService paymentFeignService;

    public ResponseUtils toPay(PayeeOrderParam payeeOrderParam){
        log.info("支付参数:{}",payeeOrderParam.toJson());
        ResponseUtils responseUtils = paymentFeignService.toPay(payeeOrderParam.toJson());
        log.info("支付返回值:{}", JSON.toJSONString(responseUtils));
        return responseUtils;
    }

    public ResponseUtils<PayeeOrderResponseDto> refund(RefundDto refundDto){
        log.info("退款参数:{}",refundDto);
        ResponseUtils<PayeeOrderResponseDto> responseUtils = paymentFeignService.refund(refundDto);
        log.info("退款返回:{}", JSON.toJSONString(responseUtils));
        if(responseUtils == null || !responseUtils.success()){
            ResponseUtils<PayeeOrderResponseDto> query = paymentFeignService.query(refundDto.getMerchantId(), refundDto.getOutTradNo());
            log.info("退款状态返回:{}", JSON.toJSONString(query));
            return query;
        }
        return responseUtils;
    }

}
